import { asyncRoutes, constantRoutes } from '@/router'
const state = {
  // 要给侧边栏显示的导航
  routes: []
}
const mutations = {
  setRoutes(state, data) {
    // 汇集了过滤后的动态路由及原本的静态路由
    state.routes = [...constantRoutes, ...data]
  }
}
const actions = {
  filterRoutes(store, data) {
    console.log('筛选逻辑')
    console.log(asyncRoutes, '动态路由')
    const routes = asyncRoutes.filter(item => data.indexOf(item.name) !== -1)
    console.log(routes)
    store.commit('setRoutes', routes)
    // 一定要返回结果，不然外面用不了
    return routes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
